
<?php
// Author: Atef Sami
include "statics.php";
session_start();
$get_id = $_SESSION['member_id'];
if (1) // checking that all the variables are coming from the client side while $_Post is to store all the posted values from 
{

    $sqlquery13 = rsSelect("area_of_expertise_id", "area_of_expertise", array('area_of_expertise_text=', $_POST['papertype']));  // query13 tries to get thev area of expertise id in the database by comparing areaofexpertise text with the text choosen by the user and confirm the id then store this id in a new variable then it is able to insert  it in the conference table.
    if (is_string($sqlquery13))
        echo $sqlquery13;

    $row7 = mysql_fetch_assoc($sqlquery13); // $row7 stores the id in an array  and then i pinpoint the element that i need (in this case areaofexpertise id that i got from the last query)

    $area_of_expertise_id1 = $row7['area_of_expertise_id'];  // i store the element of areaofexpertise id in a new variable so i can use  it in the following insert query

    $sqlquery = iInsert("conference", array('area_of_expertise' => $area_of_expertise_id1, 'long_name' => $_POST['longname'], 'short_name' => $_POST['shortname'], "rev_startDate" => date("Y-m-d"), "rev_endDate" => $_POST['spapersub'], 'description' => $_POST['textarea'], 'creator_id' => $get_id, "place" => $_POST['place']));  //i inserted all the need data in the conference table while making sure that it was the same data the user had chosen.used from statics.php
    if (is_string($sqlquery))
        echo $sqlquery;

    $confid = mysql_insert_id(); //this query helps me to pinpoint the id of the newly created conference  and store it in the $confid after getting it  as an element of the $row array 
    $sqlquery15 = rsSelect("conference_id", "conference", array('long_name=', $_POST['conference'])); //this query tries to get the id of the old created conference id from the database and insert this new id as an element in $row8
    if (is_string($sqlquery15))
        echo $sqlquery15;

    $row8 = mysql_fetch_assoc($sqlquery15);
    $sqlquery14 = iInsert("linked_conferences", array('conference_id1' => $row8['conference_id'], 'conference_id2' => $confid)); //this query stores the id of the newly created conference  and stores the id of the old chosen conference in the linked conference table so later on we can know each conference and the linked conference  to it. 
    if (is_string($sqlquery14))
        echo $sqlquery14;

    if ($_POST['comm3'] == 'true')  // this checks that the checkbox of committee 3 is checked and return true for it  
    {

        $sqlquery3 = iInsert("conference_committee", array('conference_id' => $confid, 'committee_id' => 3));  // this query will insert in the table of the conference_committee  the id  of the created conference along with the id of the chosen committee with its right id
    }
    if ($_POST['comm2'] == 'true')  // this checks that the checkbox of committee 2 is checked and return true for it  
    {

        $sqlquery10 = iInsert("conference_committee", array('conference_id' => $confid, 'committee_id' => 2)); //  this query will insert in the table of the conference_committee  the id  of the created conference along with the id of the chosen committee with its right id
    }
    if ($_POST['comm1'] == 'true') // this checks that the checkbox of committee 1 is checked and return true for it
    {

        $sqlquery12 = iInsert("conference_committee", array('conference_id' => $confid, 'committee_id' => 1));  //  this query will insert in the table of the conference_committee  the id  of the created conference along with the id of the chosen committee with its right id
    }
    if ($_POST['custom_com'] == "true")  // if the user entered a custom committe insert that committe into committee table then fetch its id and add an entry in conference committee with the conference id and the newly acquired custom committee id
    {
        $new_committee = $_POST['custom_com_text'];
        $query = iInsert("committees", array("committee_name" => $new_committee));
        if (is_string($query))
            echo $query;
        else
        {
            $last_id = mysql_insert_id();
            $query = iInsert("conference_committee", array("conference_id" => $confid, "committee_id" => $last_id));
            if (is_string($query))
                echo $query;
        }
    }
    if ($_POST['Spaper'] == 'true') // this query checks if the checkbox of the shortpaper is selected and returns true for it then add it to conference category
    {
        $sqlquery5 = iInsert("conference_category", array('conference_id' => $confid, 'category_id' => 2, "submission_date" => $_POST['spapersub'])); // insert in the table of conference_category the id of the created conference and the right id of the category that the user had chosen
    }

    if ($_POST['Lpaper'] == 'true')// this query checks if the checkbox of the long paper is selected and returns true for it then add it to conference category
    {
        $sqlquery7 = iInsert("conference_category", array('conference_id' => $confid, 'category_id' => 3, "submission_date" => $_POST['lpapersub']));  // insert in the table of conference_category the id of the created conference and the right id of the category that the user had chosen
    }

    if ($_POST['image'] == "true") // this query checks if the checkbox of the image is selected and returns true for it then add it to conference category
    {
        $sqlquery16 = iInsert("conference_category", array("conference_id" => $confid, "category_id" => 5, "submission_date" => $_POST['isub']));
        if (is_string($sqlquery16))
            echo $sqlquery16;
    }

    if ($_POST['video'] == "true") // this query checks if the checkbox of the video is selected and returns true for it then add it to conference category
    {
        $sqlquery16 = iInsert("conference_category", array("conference_id" => $confid, "category_id" => 6, "submission_date" => $_POST['vsub']));
        if (is_string($sqlquery16))
            echo $sqlquery16;
    }
    if ($_POST['poster'] == "true") // this query checks if the checkbox of the poster is selected and returns true for it then add it to conference category
    {
        $sqlquery16 = iInsert("conference_category", array("conference_id" => $confid, "category_id" => 4, "submission_date" => $_POST['psub']));
        if (is_string($sqlquery16))
            echo $sqlquery16;
    }
    if ($_POST['other'] == "true") // this query checks if the checkbox of the custom type of submissions is selected and returns true for it then add it to conference category
    {
        $other_text = $_POST['custom_type'];
        $query = iInsert("category", array("category" => $other_text));
        if (is_string($query))
            echo $query;
        else
        {
            $last_id = mysql_insert_id();
            $sqlquery16 = iInsert("conference_category", array("conference_id" => $confid, "category_id" => $last_id, "submission_date" => $_POST['other']));
            if (is_string($sqlquery16))
                echo $sqlquery16;
        }
    }
    echo "The conference has been created successfully.";  //echo "success";
}
else
{
    echo "variables not sent";  //it is used in order to know that thee code broke before even getting to the database
}
// End of documentation
?>
